package leetcode.code1111;

import java.util.Stack;

public class Solution {

	public int[] maxDepthAfterSplit(String seq) {
		char[] cs = seq.toCharArray();
		int len = cs.length;
		int[] ans = new int[len];
		int[] level = new int[len];
		Stack<Integer> stack = new Stack<>();
		for (int i = 0; i < ans.length; i++) {
			char c = cs[i];
			if (c == '(') {
				if (!stack.isEmpty()) {
					level[i] = level[stack.peek()] + 1;
				} else {
					level[i] = 1;
				}
				stack.add(i);
			} else {
				int index = stack.pop();
				int p = level[index] & 1;
				ans[index] = p;
				ans[i] = p;
			}
		}
		return ans;
	}

}
